package com.longjianghuasheng.logistics.business.mine.viewmodel

import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt
import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.RegexUtils
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.data.model.bean.ApiResponseNoData
import com.longjianghuasheng.logistics.ext.*
import com.longjianghuasheng.logistics.network.apiService
import com.longjianghuasheng.logistics.repository.request.HttpRequestCoroutine

class EnterpriseInfoViewModel : BaseMultiStateViewModel() {


    var real_name: String = ""
    var address: String = ""
    var contact: String = ""
    var tel: String = ""
    var code: String = ""
    var card_front: String = ""
    val notify by lazy {
        MutableLiveData<ApiResponseNoData>()
    }

    val startCount by lazy {
        ObservableInt()
    }

    fun onGetCode() {

        if (!checkPhone(tel)) return
        commit({ apiService.get_code(tel?:"",2)},{
            startCount.set(60)
        })
    }


    fun company_info() {


        var isSuccess = false
        when {
            real_name.judge("请输入公司名称") -> {}
            address.judge("请输入公司地址") -> {}
            contact.judge("请输入联系人姓名") -> {}
            code.judge("请输入验证码") -> {}

            !checkPhone(tel) -> {}
            card_front.judge("请上传营业执照") -> {}

            else -> isSuccess = true
        }

        if (!isSuccess) return


        commit2({
            HttpRequestCoroutine.company_info(
                real_name,
                address,
                contact,
                tel,
                code,
                card_front
            )
        }, notify)
    }


}